package com.example.calcu;

import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	Button btnadd;
	Button btnsub;
	Button btnmul;
	Button btndiv;
	
	EditText etnum1;
	EditText etnum2;
	
	TextView tvresult;
	TextView tvnum1;
	TextView tvnum2;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		btnadd = (Button) findViewById(R.id.btnadd);
		btnsub = (Button) findViewById(R.id.btnsub);
		btnmul = (Button) findViewById(R.id.btnmul);
		btndiv = (Button) findViewById(R.id.btndiv);
		
        tvresult = (TextView) findViewById(R.id.tvresult);
        //tvnum1 = (TextView) findViewById(R.id.tvnum1);
        //tvnum2 = (TextView) findViewById(R.id.tvnum2);
        
        etnum1 = (EditText) findViewById(R.id.etnum1);
        etnum2 = (EditText) findViewById(R.id.etnum2);
        
        btnadd.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				add(etnum1.getText(),etnum2.getText());
			}
		} );
        
        btnsub.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				getsub(etnum1.getText(),etnum2.getText());
			}
		} );

        btnmul.setOnClickListener(new OnClickListener() {
	
        	@Override
        	public void onClick(View v) {
        		getmul(etnum1.getText(),etnum2.getText());
		
        	}
        } );

        btndiv.setOnClickListener(new OnClickListener() {
        	
        	@Override
        	public void onClick(View v) {
        		getdiv(etnum1.getText(),etnum2.getText());
        	}
        } );



        
       
}
        protected void add(Editable etnum1, Editable etnum2)
        {
        	float num1 = Float.parseFloat(etnum1.toString());
        	float num2 = Float.parseFloat(etnum2.toString());
        	float result = num1 + num2;
        	tvresult.setText(String.valueOf(result));
        }
        
        protected void getsub(Editable etnum1, Editable etnum2)
        {
        	float num1 = Float.parseFloat(etnum1.toString());
        	float num2 = Float.parseFloat(etnum2.toString());
        	float result = num1 - num2;
        	tvresult.setText(String.valueOf(result));      
        }
        
        protected void getmul(Editable etnum1, Editable etnum2)
        {
        	float num1 = Float.parseFloat(etnum1.toString());
        	float num2 = Float.parseFloat(etnum2.toString());
        	float result = num1 * num2;
        	tvresult.setText(String.valueOf(result));
        }
        
        protected void getdiv(Editable etnum1, Editable etnum2)
        {
        	float num1 = Float.parseFloat(etnum1.toString());
        	float num2 = Float.parseFloat(etnum2.toString());
        	float result = num1 / num2;
        	tvresult.setText(String.valueOf(result));  
        }
}